package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.dao.StatisticsOfDistributionOfProvincesMapper;
import com.jy.wms.dao.WmsProvinceRankingReportMapper;
import com.jy.wms.pojo.WmsOrderDistribution;
import com.jy.wms.pojo.WmsOrderDistributionStatistics;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class StatisticsOfDistributionOfProvincesService extends BaseService<StatisticsOfDistributionOfProvincesMapper,WmsOrderDistribution> {


    /**
     * 各省订单分布统计（根据时间查询）
     *
     * @param
     * @return list
     */
    public JSONObject orderdistributionstatistics(WmsOrderDistribution WmsOrderDistribution, String hzid, String ckid) throws IOException {
        //将数据添加到map集合中
        JSONObject allJson = new JSONObject();

       /* //时间
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(WmsOrderDistribution.getFpsj_start()!=null){
            java.sql.Date date =new java.sql.Date(new Long(WmsOrderDistribution.getFpsj_start()));
            WmsOrderDistribution.setFpsj_start(sdf.format(date));
        }
        if(WmsOrderDistribution.getFpsj_end()!=null){
            java.sql.Date date=new Date(new Long(WmsOrderDistribution.getFpsj_end()));
            WmsOrderDistribution.setFpsj_end(sdf.format(date));
        }*/

        if(WmsOrderDistribution.getFpsj_start()!=null && WmsOrderDistribution.getFpsj_end()!=null){
            /*String start_time = WmsOrderDistribution.getFpsj_start();
            String End_time=WmsOrderDistribution.getFpsj_end();*/

            PageHelper.startPage(WmsOrderDistribution.getPage(), WmsOrderDistribution.getRows());
            Page<WmsOrderDistributionStatistics> order = (Page<WmsOrderDistributionStatistics>)dao.orderdistributionstatistics(WmsOrderDistribution.getFpsj_start(),WmsOrderDistribution.getFpsj_end(), hzid, ckid);

            JSONArray array = JSONArray.fromObject(order);
            allJson = SetStatus.setSearchType(array.toString(), (int) order.getTotal());
            allJson.put("contentList", order);
        }
        return allJson;
    }


    /**
     * 各省订单分布统计报表导出（根据时间查询）
     *
     * @param
     * @return list
     */

    public List<WmsOrderDistributionStatistics> baseSelectBathPrimaryKeys(WmsOrderDistributionStatistics WmsOrderDistributionStatistics, String hzid, String ckid) {
        //时间
       /* SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(WmsOrderDistributionStatistics.getFpsj_start()!=null){
            java.sql.Date date =new java.sql.Date(new Long(WmsOrderDistributionStatistics.getFpsj_start()));
            WmsOrderDistributionStatistics.setFpsj_start(sdf.format(date));
        }
        if(WmsOrderDistributionStatistics.getFpsj_end()!=null){
            java.sql.Date date=new Date(new Long(WmsOrderDistributionStatistics.getFpsj_end()));
            WmsOrderDistributionStatistics.setFpsj_end(sdf.format(date));
        }*/
        List<WmsOrderDistributionStatistics> order = dao.orderdistributionstatisticsExport(WmsOrderDistributionStatistics);

        return order;
    }
}
